<?php

if(!defined('IN_UCHOME')) {
	exit('Access Denied');
}

//获取活动ID
(intval($_GET['aid']) && $aid = (int)$_GET['aid']) || showmessage('not_find_activity');
//验证活动是否通过审核切未被关闭
$query = "SELECT * FROM ".tname('activity')." WHERE id = ".$aid." LIMIT 0,1";
$query = $_SGLOBAL['db']->query($query);
$activity = $_SGLOBAL['db']->fetch_array($query);
//如果未通过审核,提示用户
$activity['a_status'] != 1 && showmessage('not_find_activity');

//获取该活动的推广排行
$query = "SELECT sp.uid,sp.s_count,space.cname,m.username FROM ".tname('spread').
		" AS sp LEFT JOIN ".tname('spacefield')." AS space ON space.uid = sp.uid LEFT JOIN ".
		tname('member')." AS m ON m.uid = sp.uid WHERE sp.s_type = 0 AND sp.o_id = ".$aid." ORDER BY sp.s_count DESC LIMIT 0,10";
$query = $_SGLOBAL['db']->query($query);
while($value = $_SGLOBAL['db']->fetch_array($query)){
	$spread[] = $value;
}

//获取参与活动的人
$query = "SELECT pa.*,space.cname,m.username FROM ".tname('participate').
		" AS pa LEFT JOIN ".tname('spacefield')." AS space ON space.uid = pa.uid LEFT JOIN ".
		tname('member')." AS m ON m.uid = pa.uid WHERE pa.aid = ".$aid." ORDER BY ontime DESC LIMIT 0,18";
$query = $_SGLOBAL['db']->query($query);
while($value = $_SGLOBAL['db']->fetch_array($query)){
	$participate[] = $value;
}

//记录浏览人数
$setarr['a_views'] = $activity['a_views'] + 1;
$activity['a_views'] ++ ;
updatetable('activity', $setarr, 'id = '.$aid);

include_once template("activity_view");

//剩余时间换算
function lasttime($time){
	//计算时间差
	$difference = $time - time();
	if($difference < 0)return '<font>对不起,活动已结束</font>';
	//根据差值计算剩余时间的可视数据信息
	$units = array('天','小时','分','秒');
	$areas = array(3600*24,3600,60,1);
	foreach($areas as $key => $value){
		$string .= '<font>' . intval($difference / $value) . '</font>' . $units[$key];
		$difference -= intval($difference / $value) * $value;
	}
	return $string;
}

//时间格式重组
function newDate($time){return date('Y-m-d H:i:s',$time);
	$weeks = array('星期日','星期一','星期二','星期三','星期四','星期五','星期六');
	$week = $weeks[date('w',$time)];
	return date('m-d',$time).' '.$week.' '.date('H:i',$time);
}